import React, {lazy} from 'react';
import './App.less';
import {useAuth, useMount} from "utils";
import {getCookie} from "utils/cookies";
import {useAsync} from "utils/useAsync";
import {FullPageLoading} from "components/lib";
import {BrowserRouter} from "react-router-dom";
import {ConfigProvider} from 'antd'
import zhCN from 'antd/es/locale/zh_CN';

const Login = lazy(() => import("views/login"));
const Home = lazy(() => import("views/home"));


const App = () => {
    const {getInfo} = useAuth()
    const {run, isLoading} = useAsync()
    const token = getCookie('mic-token')
    useMount(() => {
        if (token) {
            run(getInfo())
        }
    })
    return (
        <BrowserRouter>
            <ConfigProvider locale={zhCN}>
                <React.Suspense fallback={<FullPageLoading/>}>
                    {token ? !isLoading ? <Home/> : <FullPageLoading/> : <Login/>}
                </React.Suspense>
            </ConfigProvider>
        </BrowserRouter>
    );
}

export default App;
